package cn.zshprint.serein.controller;

import cn.zshprint.serein.entity.Shop;
import cn.zshprint.serein.pojo.ResultBean;
import cn.zshprint.serein.service.ShopService;
import cn.zshprint.serein.vo.ShopVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Shop)表控制层
 *
 * @author makejava
 * @since 2021-08-03 08:33:32
 */
@RestController
@RequestMapping("shop")
public class ShopController {
    /**
     * 服务对象
     */
    @Resource
    private ShopService shopService;

    /**
     * 选择一个
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ResultBean<Shop> selectOne(Integer id) {
        return new ResultBean<Shop>(shopService.selectOne(id));
    }


    /**
     * 选择所有
     *
     * @return {@link ResultBean<List<Shop>>}
     */
    @GetMapping("selectAll")
    public ResultBean<List<Shop>> selectAll() {
        return new ResultBean<List<Shop>>(shopService.selectAll());
    }

    /**
     * 选择所有
     *
     * @return {@link ResultBean<List<Shop>>}
     */
    @GetMapping("selectAllAllow")
    public ResultBean<List<Shop>> selectAllAllow() {
        return new ResultBean<List<Shop>>(shopService.selectAllAllow());
    }

    /**
     * 选择所有
     *
     * @return {@link ResultBean<List<Shop>>}
     */
    @GetMapping("selectAllBan")
    public ResultBean<List<Shop>> selectAllBan() {
        return new ResultBean<List<Shop>>(shopService.selectAllBan());
    }

    @GetMapping("selectNotOperating")
    public ResultBean<List<Shop>> selectNotOperating() {
        return new ResultBean<List<Shop>>(shopService.selectNotOperating());
    }

    @GetMapping("selectYetOperating")
    public ResultBean<List<Shop>> selectYetOperating() {
        return new ResultBean<List<Shop>>(shopService.selectYetOperating());
    }

    /**
     * 保存一个
     * 通过名字查询的使用es
     * 在此不设置api
     *
     * @param name        的名字
     * @param username    用户名
     * @param image       图像
     * @param description 描述
     * @return {@link ResultBean<Integer>}
     */

    @PostMapping("saveOne")
    public ResultBean<Integer> saveOne(@RequestParam("name") String name, @RequestParam("username") String username, @RequestParam(value = "image", required = false) String image, @RequestParam("desc") String description) {
        return new ResultBean<Integer>(shopService.saveOne(name, username, image, description));
    }

    /**
     * 节省一个json
     *
     * @param shopVO 商店签证官
     * @return {@link ResultBean<Integer>}
     */
    @PostMapping("saveOneByJson")
    public ResultBean<Integer> saveOneByJson(@RequestBody ShopVO shopVO) {
        return new ResultBean<Integer>(shopService.saveOneByJson(shopVO));
    }

    /**
     * 更新一个
     *
     * @param id       id
     * @param username 用户名
     * @param name     的名字
     * @param desc     desc
     * @param image    图像
     * @return {@link ResultBean<Integer>}
     */
    @PutMapping("updateOne")
    public ResultBean<Integer> updateOne(@RequestParam(value = "id") Integer id, @RequestParam(value = "username") String username, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "desc", required = false) String desc, @RequestParam(value = "image", required = false) String image) {
        return new ResultBean<Integer>(shopService.updateOne(id, username, name, desc, image));
    }

    /**
     * 更新一个
     *
     * @param shop 商店签证官
     * @return {@link ResultBean<Integer>}
     */
    @PutMapping("updateOneByJson")
    public ResultBean<Integer> updateOneByJson(@RequestBody Shop shop) {
        return new ResultBean<Integer>(shopService.updateOneByJson(shop));
    }

    /**
     * 删除一个
     *
     * @param id id
     * @return {@link ResultBean<Integer>}
     */
    @DeleteMapping("deleteOne/{id}")
    public ResultBean<Integer> deleteOne(@PathVariable Integer id) {
        return new ResultBean<Integer>(shopService.deleteOne(id));
    }

    /**
     * 恢复
     *
     * @param id id
     * @return {@link ResultBean<Integer>}
     */
    @PutMapping("restore/{id}")
    public ResultBean<Integer> restore(@PathVariable Integer id) {
        return new ResultBean<Integer>(shopService.restore(id));
    }

    @PutMapping("open/{id}")
    public ResultBean<Integer> open(@PathVariable Integer id) {
        return new ResultBean<Integer>(shopService.open(id));
    }

    @PutMapping("close/{id}")
    public ResultBean<Integer> close(@PathVariable Integer id) {
        return new ResultBean<Integer>(shopService.close(id));
    }
}